<?php include APPLICATION_PATH . '/modules/default/layouts/scripts/content-outer-start.phtml'; ?>
<script>
    function validateForm(){
        var numdonhang = document.getElementById("numDH").value;
        if(numdonhang > 0){
            var intRegex = /^\d+$/;
            if(intRegex.test(numdonhang)) {
               return true;
            } else{
                alert("Bạn cần nhập số đơn hàng là số nguyên dương.");
                return false;
            }
        } else{
            alert("Bạn nhập số đơn hàng chưa hợp lệ.");
            return false;
        }
    }
    $(document).ready(function() {
        
    });
</script>
<div align="center" style="height: auto;">
    <div class="form_row" style="margin-top: 0px; margin-bottom: 10px; height: auto;">
        <h3 style="margin-top: 5px; margin-bottom: 20px;">Thống kê số lượng khách hàng giới thiệu được nhiều đơn hàng</h3>
    </div>
    <form id="mainform" action="<?php echo $this->baseUrl . '/default/loctheodonhang/index' ?>" method="post" onsubmit="return validateForm();">
        <div class="form_row">
            <div class="form_row">
                <div class="label_name_1"><label for="owner" class="label_css">Số đơn hàng: </label> </div>
                <div class="float_l">
                    <?php $numDH = $this->numDH > 0 ? $this->numDH : 10; ?>
                    <input type="text" id="numDH" name="numDH" value="<?php echo $numDH; ?>" class="input_css" />
                </div>
            </div>
            
            <div class="form_row">
                <div class="label_name_1"><label for="owner" class="label_css">Tháng: </label> </div>
                <div class="float_l" style="width: 620px; margin-left: 30px;">
                    <div class="float_l" style="width: 130px; margin-left: 5px;">
                        <select id="numThang" name="numThang" class="select_css" style="background-color: #FFFFFF; width: 120px;">
                            <?php
                            $numThang = $this->numThang > 0 ? $this->numThang : date("m");
                            for($i=1; $i<=12; $i++) {
                                if($i == $numThang){
                                    echo '<option selected value="' . $i . '">' . $i . '</option>';
                                } else{
                                    echo '<option value="' . $i . '">' . $i . '</option>';
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="float_l" style="margin-left: 5px;">
                        <select id="numNam" name="numNam" class="select_css" style="background-color: #FFFFFF; width: 120px;">
                            <?php
                            $numNam = $this->numNam > 2012 ? $this->numNam : date("Y");
                            for($i=2013; $i<=2030; $i++) {
                                if($i == $numNam){
                                    echo '<option selected value="' . $i . '">' . $i . '</option>';
                                } else{
                                    echo '<option value="' . $i . '">' . $i . '</option>';
                                }
                            }
                            ?>
                        </select>
                    </div>
                </div>
            </div>
            
            <div class="" align="center">
                <input type="submit" id="timKiem" value="Tìm kiếm" class="button gray" style="margin-right: 570px;">
            </div>
        </div>
        
        <div class="form_row" style="margin-top: 50px; margin-bottom: 10px;">
            <h3 style="margin-top: 5px;">Danh sách khách hàng</h3>
        </div>
        
        <div class="form_row">
            <table class="Grid" cellspacing="0" cellpadding="3" rules="all" border="1" id="tableData" style="width:100%;border-collapse:collapse;">
                <tbody id="tableDHCC">
                    <tr class="GridHeader" align="center">
                        <th align="center" scope="col">STT</th>
                        <th align="center" scope="col">Mã khách hàng</th>
                        <th align="center" scope="col">Tên khách hàng</th>
                        <th align="center" scope="col">Số đơn hàng</th>
                    </tr>
                    <?php
                    if ($this->tableDataDSDH) {
                        $i=1;
                        foreach ($this->tableDataDSDH as $row) {
                    ?>
                            <tr class="GridItem" align="center">
                                <th align="center" scope="col"><?php echo $i;?></th>
                                <th align="center" scope="col"><?php echo $row['maDL'];?></th>
                                <th align="center" scope="col"><?php echo $row['tenDL'];?></th>
                                <th align="center" scope="col"><?php echo $row['slDH'];?></th>
                            </tr>
                    <?php
                            $i = $i + 1;
                        }
                    } else{
                    ?>
                        <tr class="GridItem" align="center">
                            <th align="center" scope="col" colspan="4">Không có khách hàng nào</th>
                        </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        
    </form>
</div>
<?php include APPLICATION_PATH . '/modules/default/layouts/scripts/content-outer-end.phtml'; ?>
